
import win32gui
from PIL import ImageGrab,Image
import win32con
# from Utility.Colors import DEFAULT, RED

hwnd = win32gui.FindWindow(0, "江西快三")

print(hwnd)

# if not hwnd:
#     print(RED, 'window not found!', DEFAULT)
# else:
#     print(hwnd)

win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)  # 强行显示界面后才好截图
win32gui.SetForegroundWindow(hwnd)  # 将窗口提到最前
#  裁剪得到全图
game_rect = win32gui.GetWindowRect(hwnd)
src_image = ImageGrab.grab(game_rect)
# src_image = ImageGrab.grab((238, 242, 238+597, 242+21))
src_image.show()
src_image.save("pixel2.png")

im = Image.open("pixel2.png")  # 打开图片句柄
box = (238, 242, 238+597, 242+21) # 设定裁剪区域
region = im.crop(box)  # 裁剪图片，并获取句柄region
region.save("3.png")  # 保存图片

# import PIL
# import PIL.Image, PIL.ImageGrab
#
# bbox = (300, 300, 300+100, 300+100)
# img = PIL.ImageGrab.grab(bbox)
# img.save("pixel.png")
# img.show()
